#ifndef CSR_BT_GATT_SEF_H__
#define CSR_BT_GATT_SEF_H__
/******************************************************************************
 Copyright (c) 2010-2021 Qualcomm Technologies International, Ltd.
 All Rights Reserved.
 Qualcomm Technologies International, Ltd. Confidential and Proprietary.

 REVISION:      $Revision: #8 $
******************************************************************************/

#include "csr_synergy.h"
#include "csr_bt_gatt_main.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Advertisment priority */
#define CSR_BT_GATT_ADV_PRIO_LOW                  ((CsrUint8) 0x00)
#define CSR_BT_GATT_ADV_PRIO_MEDIUM               ((CsrUint8) 0x01)
#define CSR_BT_GATT_ADV_PRIO_HIGH                 ((CsrUint8) 0x02)

/* Covers Registration and Un-register an application instance to Gatt */
CsrBool CsrBtGattRegisterReqHandler(GattMainInst *inst);
CsrBool CsrBtGattUnregisterReqHandler(GattMainInst *inst);
#ifdef CSR_BT_GATT_INSTALL_EATT
CsrBool CsrBtGattPriorityReqHandler(GattMainInst *inst);
CsrBool CsrBtGattReadMultiVarReqHandler(GattMainInst *inst);
CsrBool CsrBtGattReadMultiVarRspHandler(GattMainInst *inst);
#ifdef SYNERGY_QUAL
CsrBool CsrBtGattEattDisconnectReqHandler(GattMainInst *inst);
#else
#define CsrBtGattEattDisconnectReqHandler NULL
#endif /* SYNERGY_QUAL */
#else
#define CsrBtGattPriorityReqHandler NULL
#define CsrBtGattReadMultiVarReqHandler NULL
#define CsrBtGattReadMultiVarRspHandler NULL
#define CsrBtGattEattDisconnectReqHandler NULL
#endif /* CSR_BT_GATT_INSTALL_EATT */

#if defined(CSR_BT_GATT_INSTALL_SERVER_LONG_WRITE_OFFSET) || defined(CSR_BT_GATT_INSTALL_CLIENT_LONG_READ_OFFSET)
CsrBool CsrBtGattConfigModeReqHandler(GattMainInst *inst);
#else
#define CsrBtGattConfigModeReqHandler NULL
#endif

/* Covers DataBase Configuration */
#ifndef CSR_BT_GATT_INSTALL_FLAT_DB
CsrBool CsrBtGattDbAllocReqHandler(GattMainInst *inst);
CsrBool CsrBtGattDbDeallocReqHandler(GattMainInst *inst);
CsrBool CsrBtGattDbAddReqHandler(GattMainInst *inst);
CsrBool CsrBtGattDbRemoveReqHandler(GattMainInst *inst);
#define CsrBtGattFlatDbRegisterReqHandler NULL
#define CsrBtGattFlatDbRegisterHandleRangeReqHandler NULL
#else
#define CsrBtGattDbAllocReqHandler NULL
#define CsrBtGattDbDeallocReqHandler NULL
#define CsrBtGattDbAddReqHandler NULL
#define CsrBtGattDbRemoveReqHandler NULL
CsrBool CsrBtGattFlatDbRegisterReqHandler(GattMainInst *inst);
CsrBool CsrBtGattFlatDbRegisterHandleRangeReqHandler(GattMainInst *inst);
#endif

CsrBool CsrBtGattDbAccessResHandler(GattMainInst *inst);

/* Covers Server Initiated Notification and Indication  */
CsrBool CsrBtGattEventSendReqHandler(GattMainInst *inst);
void CsrBtGattServiceChangedIndicationSend(GattMainInst         *inst, 
                                           CsrBtGattConnElement *conn,
                                           CsrBtGattHandle      startHandle,
                                           CsrBtGattHandle      endHandle); 

/* Covers LE observe/broadcast procedures */
CsrBool CsrBtGattStopScanProcedure(GattMainInst        *inst, 
                                   CsrBtGattAppElement *app, 
                                   CsrUint16           context);

void CsrBtGattStartScanProcedure(GattMainInst *inst, CsrUint16 context);

void CsrBtGattStartScanCentralProcedure(GattMainInst   *inst, 
                                        CsrUint16      scanInterval,
                                        CsrUint16      scanWindow,
                                        CsrUint16      centralAddrCount, 
                                        CsrBtTypedAddr *centralAddrList,
                                        CsrUint16      context);

CsrBool CsrBtGattStopAdvertiseProcedure(GattMainInst        *inst, 
                                        CsrBtGattAppElement *app, 
                                        CsrUint16           context);

CsrBtResultCode CsrBtGattModifyAdvertiseProcedure(GattMainInst          *inst,
                                                  CsrBtGattAppElement   *app, 
                                                  CsrBool               releaseWhiteList,
                                                  CsrUint16             context,
                                                  CsrUint8              filterPolicy);

#ifndef EXCLUDE_CSR_BT_GATT_GAP_MODULE
/* Covers LE connection oriented procedures */
CsrBool CsrBtGattCentralReqHandler(GattMainInst *inst);
CsrBool CsrBtGattPeripheralReqHandler(GattMainInst *inst);
CsrBool CsrBtGattScanReqHandler(GattMainInst *inst);
CsrBool CsrBtGattAdvertiseReqHandler(GattMainInst *inst);
CsrBool CsrBtGattBredrConnectReqHandler(GattMainInst *inst);
CsrBool CsrBtGattBredrAcceptReqHandler(GattMainInst *inst);
void CsrBtGattDisconnectRestoreHandler(GattMainInst *inst, CsrBtGattQueueElement *qElem, CsrUint16 mtu);

CsrBool CsrBtGattDisconnectReqHandler(GattMainInst *inst);
/* LE scan/advertise/connection parameters */
CsrBool CsrBtGattParamScanReqHandler(GattMainInst *inst);
CsrBool CsrBtGattParamAdvertiseReqHandler(GattMainInst *inst);
#ifdef CSR_BT_INSTALL_GATT_PARAM_CONNECTION
CsrBool CsrBtGattParamConnectionReqHandler(GattMainInst *inst);
#else
#define CsrBtGattParamConnectionReqHandler NULL
#endif
/* Whitelist control */
CsrBool CsrBtGattWhitelistAddReqHandler(GattMainInst *inst);
CsrBool CsrBtGattWhitelistClearReqHandler(GattMainInst *inst);
CsrBool CsrBtGattWhitelistReadReqHandler(GattMainInst *inst);
CsrBool CsrBtGattParamConnUpdateReqHandler(GattMainInst *inst);
CsrBool CsrBtGattParamConnUpdateResHandler(GattMainInst *inst);
#else
#define CsrBtGattCentralReqHandler NULL
#define CsrBtGattPeripheralReqHandler NULL
#define CsrBtGattScanReqHandler NULL
#define CsrBtGattAdvertiseReqHandler NULL
#define CsrBtGattBredrConnectReqHandler NULL
#define CsrBtGattBredrAcceptReqHandler NULL
#define CsrBtGattDisconnectReqHandler NULL
/* LE scan/advertise/connection parameters */
#define CsrBtGattParamScanReqHandler NULL
#define CsrBtGattParamAdvertiseReqHandler NULL
#ifdef CSR_BT_INSTALL_GATT_PARAM_CONNECTION
#define CsrBtGattParamConnectionReqHandler NULL
#endif
/* Whitelist control */
#define CsrBtGattWhitelistAddReqHandler NULL
#define CsrBtGattWhitelistClearReqHandler NULL
#define CsrBtGattWhitelistReadReqHandler NULL
#define CsrBtGattParamConnUpdateReqHandler NULL
#define CsrBtGattParamConnUpdateResHandler NULL
#endif /* EXCLUDE_CSR_BT_GATT_GAP_MODULE */

#ifndef EXCLUDE_CSR_BT_SC_MODULE
/* Security */
CsrBool CsrBtGattSecurityReqHandler(GattMainInst *inst);
#else
/* Security */
#define CsrBtGattSecurityReqHandler NULL
#endif

/* Covers SDS Register/Unregister Error handling */
void CsrBtGattSdsRestoreHandler(GattMainInst *inst, CsrBtGattQueueElement *qElem, CsrUint16 mtu);
void CsrBtGattSdsRequestHandler(GattMainInst *inst, CsrUint16 event);
#ifndef CSR_BT_GATT_INSTALL_FLAT_DB
void CsrBtGattBrEdrSupportHandler(GattMainInst *inst,
                                  CsrBtGattDb  *db);
#endif
void CsrBtGattBredrStartDiscovery(GattMainInst *inst, 
                                  CsrBtConnId btConnId, 
                                  CsrBtGattConnElement *conn);
void CsrBtGattBredrInit(GattMainInst *inst);
void CsrBtGattBredrDeinit(GattMainInst *inst);
void CsrBtGattInitSecurity(void);

void CsrBtGattCmSdsRegisterCfmHandler(GattMainInst *inst);
void CsrBtGattCmSdsUnregisterCfmHandler(GattMainInst *inst);
void CsrBtGattCmL2caConnectAcceptCfmHandler(GattMainInst *inst,
                                            CsrBtCmL2caConnectAcceptCfm *cfm);

/* Covers item 1, Server Configuration, in the GATT feature table */
void CsrBtGattExchangeMtuHandler(GattMainInst   *inst, 
                                 CsrUint16      mtu, 
                                 CsrBtConnId    btConnId, 
                                 CsrBtTypedAddr address);

/* Covers item 2, Primary Service Discovery, in the GATT feature table  */
CsrBool CsrBtGattDiscoverServicesReqHandler(GattMainInst *inst);

/* Covers item 3, Relationship Discovery, in the GATT feature table */
CsrBool CsrBtGattFindInclServicesReqHandler(GattMainInst *inst);

/* Covers item 4, Characteristic Discovery, in the GATT feature table */
CsrBool CsrBtGattDiscoverCharacReqHandler(GattMainInst *inst);

/* Covers item 5, Characteristic Descriptor Discovery, in the GATT feature table */
CsrBool CsrBtGattDiscoverCharacDescriptorsReqHandler(GattMainInst *inst);

/* Covers item 6, Characteristic Value Read, and  item 10, 
   Read Characteristic Descriptor Value,in the GATT feature table */
CsrBool CsrBtGattReadReqHandler(GattMainInst *inst);
CsrBool CsrBtGattReadByUuidReqHandler(GattMainInst *inst);
CsrBool CsrBtGattReadMultiReqHandler(GattMainInst *inst);
CsrBool CsrBtGattReadByUuidSecurityHandler(void            *gattInst,
                                           void            *qElem,
                                           CsrBtResultCode result, 
                                           CsrBtSupplier   supplier);

/* Covers item 7, Characteristic Value Write, in the GATT feature table */
void CsrBtGattGetAttPrepareWriteSend(CsrBtGattConnElement  *conn,
                                     CsrBtGattQueueElement *qElem,
                                     CsrUint16             prepareWriteOffset,
                                     CsrUint16             mtu,
                                     CsrUint16             valueLength,
                                     CsrUint8              *value);

CsrBool CsrBtGattWriteReqHandler(GattMainInst *inst);
#ifndef EXCLUDE_CSR_BT_SC_MODULE
CsrBool CsrBtGattPrepareWriteSecurityHandler(CsrBtGattConnElement  *conn,
                                             void         *gattInst, 
                                             void            *qElem,
                                             CsrBtResultCode result, 
                                             CsrBtSupplier   supplier);

CsrBool CsrBtGattWriteRequestSecurityHandler(void            *gattInst, 
                                             void            *qElem,
                                             CsrBtResultCode result, 
                                             CsrBtSupplier   supplier);
#else
#define CsrBtGattPrepareWriteSecurityHandler NULL
#define CsrBtGattWriteRequestSecurityHandler NULL
#endif /* !EXCLUDE_CSR_BT_SC_MODULE */

/* Event Mask Handler*/
CsrBool CsrBtGattSetEventMaskReqHandler(GattMainInst *inst);

/* Cancel */
CsrBool CsrBtGattCancelReqHandler(GattMainInst *inst);

/* To start the Private Read By UUID. E.g CSR_BT_GATT_UUID_DEVICE_NAME_CHARAC or CSR_BT_GATT_UUID_SERVICE_CHANGED_CHARAC  */
void CsrBtGattReadByUuidPrivateHandler(GattMainInst *inst, CsrBtUuid16 uuidToRead, CsrBtConnId btConnId);

/* Write value to the Client Configuration Despriptor which belongs to the Service Changed Characteristic */
void CsrBtGattWriteServiceChangedHandler(CsrBtGattQueueElement *qElem, CsrBtGattCliConfigBits configValue);

/* Private stuff */
void CsrBtGattReadRemoteLeNameReqHandler(GattMainInst *inst);

#ifdef CSR_BT_INSTALL_GATT_BREDR
CsrBool CsrBtGattConnectBredrReqHandler(GattMainInst *inst);

CsrBool CsrBtGattAcceptBredrReqHandler(GattMainInst *inst);

CsrBool CsrBtGattCancelAcceptBredrReqHandler(GattMainInst *inst);

CsrBool CsrBtGattConnectBredrResHandler(GattMainInst *inst);

CsrBool CsrBtGattDisconnectBredrReqHandler(GattMainInst *inst);
#else
#define CsrBtGattConnectBredrReqHandler NULL

#define CsrBtGattAcceptBredrReqHandler NULL

#define CsrBtGattCancelAcceptBredrReqHandler NULL

#define CsrBtGattConnectBredrResHandler NULL

#define CsrBtGattDisconnectBredrReqHandler NULL
#endif

#ifdef CSR_BT_INSTALL_LE_PRIVACY_1P2_SUPPORT
void CsrBtGattReadRemoteRpaOnlyCharReqHandler(GattMainInst *inst);
#endif

/* Prototypes - free_downsteam */
void CsrBtGattFreeDownstreamMessageContents(CsrUint16 eventClass, void *message);

#ifdef CSR_BT_GATT_INSTALL_CLIENT_HANDLE_SUBSCRIPTION
CsrBool CsrBtGattSubscriptionReqHandler(GattMainInst *inst);
/* Covers item 8 and 9, Characteristic Value Indication/Notification, in the GATT feature table */
CsrBool CsrBtGattWriteClientConfigurationReqHandler(GattMainInst *inst);
#else
#define CsrBtGattSubscriptionReqHandler NULL
#define CsrBtGattWriteClientConfigurationReqHandler NULL
#endif

#ifdef CSR_BT_GATT_INSTALL_CLIENT_SERVICE_REGISTRATION
CsrBool CsrBtGattClientRegisterServiceReqHandler(GattMainInst *inst);
CsrBool CsrBtGattClientIndicationRspHandler(GattMainInst *inst);
#else
#define CsrBtGattClientRegisterServiceReqHandler NULL
#define CsrBtGattClientIndicationRspHandler NULL
#endif /* CSR_BT_GATT_INSTALL_CLIENT_SERVICE_REGISTRATION */

#ifdef EXCLUDE_CSR_BT_GATT_GAP_MODULE
CsrBool CsrBtGattClientExchangeMtuReqHandler(GattMainInst *inst);
CsrBool CsrBtGattRemoteClientExchangeMtuResHandler(GattMainInst *inst);
CsrBool CsrBtGattConfigReqHandler(GattMainInst *inst);
#else
#define CsrBtGattClientExchangeMtuReqHandler NULL
#define CsrBtGattRemoteClientExchangeMtuResHandler NULL
#define CsrBtGattConfigReqHandler NULL
#endif

#if defined(CSR_BT_GATT_CACHING) && !defined(CSR_BT_GATT_INSTALL_FLAT_DB)
CsrBool CsrBtGattDbCommitReqHandler(GattMainInst *inst);
#else
#define CsrBtGattDbCommitReqHandler NULL
#endif

#ifdef __cplusplus
}
#endif

#endif /* CSR_BT_GATT_SEF_H__ */

